<!--
@license
Copyright 2016 The TensorFlow Authors. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
-->

<link rel="import" href="tf-op-table.html">
<link rel="import" href="tf-op-details.html">
<link rel="import" href="utils.html">

<!--
  tf-op-profile is a view within the tf-profile-dashboard.
  It shows a hierarchical profile of XLA operations broken (a tf-op-table).
  A single node can be selected, and its details are shown (with tf-op-details).
  Summary information and the most expensive op are described at the top, as
  a gentle introduction.
-->
<dom-module id="tf-op-profile">
  <template>
    <style>
/* The detail box lives in the left navigation column.
 * This is weird, but makes good use of our horizontal space. */
tf-op-details {
  position: fixed;
  /* don't set top, so it ends up next to tf-op-table */
  margin-top: 10em;
  left: 16px;
  width: 330px;
}
:host {
  display: block;
  margin-right: 1.5em;
}
#description {
  margin-bottom: 2em;
  width: 600px;
}
    </style>
    <div class="tf-op-profile">
      <h4>Overall TPU FLOPS utilization is
        <span style$="color:[[_textColor(_root)]]">
          [[_utilizationPercent(_root)]]</span>
      </h4>
      <div id="description">
        <p>Modifying your model's architecture, data dimensions, and improving
        the efficiency of CPU operations may help reach the TPU's FLOPS potential.
      </p></div>
      <tf-op-details hidden="[[!_active]]" node=[[_active]]></tf-op-details>
      <tf-op-table root-node="[[_root]]" active={{_active}}></tf-op-table>
    </div>
  </template>

  <script>
Polymer({
  is: 'tf-op-profile',
  properties: {
    _data: {
      type: Object,
      notify: true,
    },
    _root: {
      type: Object,
      computed: '_getRoot(_data, "byCategory")',
      notify: true,
    },
    _active: {
      type: Object,
      value: null,
      notify: true,
    },
  },
  _getRoot: function(data, breakdown) { return data[breakdown]; },
  _utilizationPercent: function(node) { return tf_op_profile.percent(tf_op_profile.utilization(node)); },
  _hasFlops: function(node) { return node.metrics.flops > 0; },
  _textColor: function(node) { return tf_op_profile.flameColor(tf_op_profile.utilization(node), 0.7); },
});
  </script>
</dom-module>
